class Solution:
    def minCost(self, colors: str, neededTime: List[int]) -> int:
        ans = mat_x = 0
        for i, t in enumerate(neededTime):
            ans += t 
            if t > mat_x:
                mat_x = t 
            if i == len(colors) - 1 or colors[i] != colors[i + 1]:
                ans -= mat_x   # 保留耗时最大的气球
                mat_x = 0
        return ans